import { ValidationPipe } from "@nestjs/common";
import { NestFactory } from "@nestjs/core";
import { AppModule } from "./app.module";
import { GlobalExceptionFilter } from "./common/filters/global-exception.filter";
import { GlobalResponseInterceptor } from "./common/interceptors/global-response.interceptor";

import { DocumentBuilder, SwaggerModule } from "@nestjs/swagger";
async function bootstrap() {
  const app = await NestFactory.create(AppModule);

  // 启用全局验证管道
  app.useGlobalPipes(
    new ValidationPipe({
      whitelist: true,
      transform: true,
      forbidNonWhitelisted: true,
    })
  );

  // 启用全局异常过滤器
  app.useGlobalFilters(new GlobalExceptionFilter());

  // 启用全局响应拦截器
  app.useGlobalInterceptors(new GlobalResponseInterceptor());

  // 启用CORS
  app.enableCors();
  const options = new DocumentBuilder()
    .setTitle("vue3-admin")
    .setDescription(
      "Background system based on Nest.js + Vue3 full stack development"
    )
    .setVersion("1.0")
    .build();
  const document = SwaggerModule.createDocument(app, options);
  SwaggerModule.setup("docs", app, document);

  await app.listen(3001); // 使用3003端口
  console.log("应用程序正在监听端口 3003");
}
bootstrap();
